package com.inspur.security.cbb3.kms.config.security;

import com.inspur.security.cbb3.kms.login.service.LoginAttemptService;
import com.inspur.security.cbb3.kms.utils.IpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * 登录成功监听
 *
 * @author kangxuezhong
 *
 */
@Component
public class AuthenticationSuccessEventListener implements ApplicationListener<AuthenticationSuccessEvent> {

	@Autowired
	private LoginAttemptService loginAttemptService;

	@Autowired
	private HttpServletRequest request;

	@Override
	public void onApplicationEvent(AuthenticationSuccessEvent e) {
		loginAttemptService.loginSucceeded(IpUtil.getRemoteHost(request));
	}
}
